package com.crawler.test;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import com.google.gson.JsonObject;

public class CrawlerDemo {
	public static void main(String[] args) {
		String url="http://www.dianping.com/shop/4234082";			//url
		int outTime=8000;											//超时时间
		Document doc=null;											//加载成功后的Document
		int maxRetry=3;												//重复次数
		int retryNum=0;												//尝试次数
		boolean retry=true;
		while(retry){
			try {
				doc = Jsoup.connect(url).timeout(outTime).get();
				Elements shopH1=doc.select("h1.shop-name");
				String shopName=shopH1.html().toString();
				System.out.println(shopName);
				System.out.println(doc.title());
				retry=false;
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				retryNum++;
				if(retryNum>=maxRetry){
					retry=false;
				}else {
					try {
						Thread.sleep(3000);
					} catch (InterruptedException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
			}
		}
	}
}
